package com.bayern.exsample;

import org.junit.Test;

import com.bayern.cache.FIFOCache;
import com.bayern.cache.LFUCache;
import com.bayern.cache.LRUCache;
import com.bayern.cache.MyLRUCache;

public class CacheTest 
{
	@Test
	public void FIFOCacheTest()
	{
		try 
		{
			FIFOCache<String, String> fifoCache = new FIFOCache<String, String>(3);
			fifoCache.set("1", "1");
			fifoCache.set("2", "2");
			fifoCache.set("3", "3");
			fifoCache.printCache();
			fifoCache.set("4", "4");
			System.out.println("----------------");
			fifoCache.printCache();
			fifoCache.set("5", "5");
			System.out.println("----------------");
			fifoCache.printCache();
		}
		catch (InterruptedException e)
		{
			e.printStackTrace();
		}
	}
	
	@Test
	public void LFUCacheTest()
	{
		try 
		{
			LFUCache<Integer, String> lfuCache = new LFUCache<Integer, String>(3);
			lfuCache.set(2, "2");
			lfuCache.set(1, "1");
//			lfuCache.set(2, "2");
			lfuCache.get(2);
//			lfuCache.set(1, "1");
			lfuCache.get(1);
//			lfuCache.set(2, "2");
			lfuCache.get(2);
			lfuCache.set(3, "3");
			lfuCache.set(4, "4");
			lfuCache.printCache();
		}
		catch (InterruptedException e)
		{
			e.printStackTrace();
		}
	}
	
	@Test
	public void MyLRUCacheTest()
	{
		try 
		{
			MyLRUCache<Integer, String> lruCache = new MyLRUCache<Integer, String>(3);
			lruCache.set(2, "2");
			lruCache.set(1, "1");
			lruCache.set(2, "2");
			lruCache.set(1, "1");
			lruCache.set(2, "2");
			lruCache.set(3, "3");
			lruCache.printCache();
			lruCache.set(4, "4");
			System.out.println("---------------");
			lruCache.printCache();
		}
		catch (InterruptedException e)
		{
			e.printStackTrace();
		}
	}
	
	@Test
	public void LRUCacheTest()
	{
		try 
		{
			LRUCache<Integer, String> lruCache = new LRUCache<Integer, String>(3);
			lruCache.set(2, "2");
			lruCache.set(1, "1");
			lruCache.set(2, "2");
			lruCache.set(1, "1");
			lruCache.set(2, "2");
			lruCache.set(3, "3");
			lruCache.printCache();
			lruCache.set(4, "4");
			System.out.println("---------------");
			lruCache.printCache();
		}
		catch (InterruptedException e)
		{
			e.printStackTrace();
		}
	}
}
